package org.campuscontent.config.languages;

import java.awt.FlowLayout;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.campuscontent.ui.AutomataMarqueeHandler;

public class LanguageSamplePanel extends JFrame implements LanguageListener
{
    public LanguageSamplePanel()
    {
        lm.addListener( this );
        
        setLayout( new FlowLayout() );
        button = new JButton( "Click" );
        label  = new JLabel( "empty"  );
        add( button );
        add( label  );
        
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }
    
    public void update( ResourceBundle resources )
    {
        String str = resources.getString( "graphpro.automata.popup.edit" );
        System.out.println( str );
        label.setText( str );

        pack();
        
        invalidate();
        validate();
        repaint();
    }
    
    public void test()
    {
        pack();
        setVisible( true );
        
        try
        {
            Thread.sleep( 2000 );
            lm.set( Locale.ENGLISH );
            lm.refresh();
            
            Thread.sleep( 2000 );
            lm.set( Locale.FRENCH );
            lm.refresh();
            
            Thread.sleep( 2000 );
            lm.set( Locale.GERMAN );
            lm.refresh();
            
            Thread.sleep( 2000 );
            lm.set( new Locale( "es" ) );
            lm.refresh();
        }
        catch ( Exception e )
        {
        }
    }
    
    public static void main( String[] args )
    {
        String edit = LanguageManager.str( AutomataMarqueeHandler.class, "popup.edit" );
        System.out.println( edit );
        
        new LanguageSamplePanel().test();
    }
    
    JButton button;
    JLabel  label ;
    
    LanguageManager lm = LanguageManager.getInstance();
}
